<template>
	<view class="body">
		<view class="block">
			<i class="ali-icon icon-color body-form-icon">&#xe620;</i>
			<input class="body-form-input" name="input" placeholder="请输入姓名" :value="userName" @input="getUserName" />
			<i class="ali-icon body-form-icon" style="color:#dedede" @tap="clear('userName')">&#xe604;</i>
		</view>
		<view class="block">
			<i class="ali-icon icon-color body-form-icon">&#xe658;</i>
			<input class="body-form-input" name="input" placeholder="请输入手机号" :value="userMobile" @input="getUserMobile" />
			<i class="ali-icon body-form-icon" style="color:#dedede" @tap="clear('userMobile')">&#xe604;</i>
		</view>
		<view class="block_code">
			<view class="view_code">
				<i class="ali-icon icon-color body-form-icon">&#xe6bf;</i>
				<input class="body-form-input1" name="input" placeholder="请输入验证码" :value="code" @input="getCode" />
				<i class="ali-icon body-form-icon" style="color:#dedede" @tap="clear('code')">&#xe604;</i>
			</view>
			<view class="body-form-code">
				<image :src="url" mode="widthFix" @click="getCodeImg"></image>
			</view>
		</view>
		<view class="bottom-btn">
			<button type="primary" :loading="loading" @click="onSubmit" class='btn-next'>提交</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cardId: '',
				userName: '',
				userMobile: '',
				code: '',
				url: '',
				encryptedString: '',
				loading: false,
			}
		},
		onLoad(options) {
		    this.cardId = options.cardId; 
			this.getCodeImg();
		},
		methods: {
			onSubmit(){
				let _this = this;
				if(this.userName==''){
					uni.showToast({
					   title: '请填写姓名',
					   icon: 'none',
					   duration: 2000		
					});
					return false
				}
				if(this.userName&&this.userName.length>10){
					uni.showToast({
					   title: '姓名长度不能超过10位',
					   icon: 'none',
					   duration: 2000		
					});
					return false
				}
				if(this.userMobile==''){
					uni.showToast({
					   title: '请填写手机号',
					   icon: 'none',
					   duration: 2000		
					});
					return false
				}
				let reg = /^(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[8-9])[0-9]{8}$/;
				if(!reg.test(this.userMobile)){
					uni.showToast({
					   title: '请修改手机号',
					   icon: 'none',
					   duration: 2000		
					});
					return false
				}
				if(this.code==''){
					uni.showToast({
					   title: '请填写验证码',
					   icon: 'none',
					   duration: 2000		
					});
					return false
				}
				uni.showModal({
					title: '提示',
					content: '是否立即机卡重绑？机卡重绑后请继续前往操作记录查看结果',
					success: function (res) {
						if (res.confirm) {
							_this.loading = true;
							_this.$req.userRecharge('card/unlock/imgcheck',{
								id: _this.cardId,				//cardId
								name: _this.userName,			//姓名
								phone: _this.userMobile,			//手机号
								imgCode: _this.code,				//验证码
								uid: _this.encryptedString,
							}).then(res=>{
								uni.showToast({
								   title: '请稍后到卡日志查看操作结果',
								   icon: 'none',
								   duration: 2000		
								});
							})
							_this.code = '';
							_this.encryptedString = '';
							_this.url = '';
							_this.getCodeImg()
							_this.loading = false;
						} else if (res.cancel) {
							uni.showToast({
							   title: '已取消机卡重绑操作',
							   icon: 'none',
							   duration: 2000		
							});	
						}
					}
				});		
				
			},
			getCodeImg() {
				this.$req.sendCheck('/code/send/pictureCode/uid', {}).then(res => {
					if (res._result) {
						this.encryptedString = res.data
						this.url = '/api/oceanside-send-and-check/code/send/pictureCode/' + res.data
					}
				})
			},
			getUserName(e){
				this.userName = e.detail.value;  
			},
			getUserMobile(e){
				this.userMobile = e.detail.value; 
			},
			getCode(e){
				this.code = e.detail.value;  
			},
			clear(inputName){
				return this[inputName]='';
			}
		}
	}
</script>

<style>
	.body{
		width: 90%;
		height: 90%;
		background-color: #fff;
		position: relative;
		top: 0;
		left: 0;
		margin: 0;
		padding: 0;
		padding: 10% 5%;
	}
	.block{
		width: auto;
		height: 90upx;
		position: relative;
		top: 0;
		left: 0;
		border: 1px solid #007AFF;
		border-radius: 5px;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		margin-bottom: 20px;
	}
	.body-form-icon{
		width: 9vw;
		height: 100%;
		position: relative;
		display: inline-flex;
		justify-content: center;
		align-items: center;
	}
	.body-form-input{
		width: 80%;
		height: 60upx;
		line-height: 80upx;
		outline: none;
		border-radius: 5px;
		padding: 10upx 20upx;
		font-size: 28upx;
	}
	.block_code{
		width: 100%;
		height: 90upx;
		position: relative;
		top: 0;
		left: 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.view_code{
		width: 60vw;
		height: 100%;
		position: relative;
		display: inline-flex;
		justify-content: space-between;
		align-items: center;
		border: 1px solid #007AFF;		
		border-radius: 5px;
	}
	.body-form-input1{
		width: 42vw;
		height: 60upx;
		line-height: 80upx;
		outline: none;
		background-color: white;
		border-radius: 5px;
		font-size: 28upx;
	}
	.body-form-code{
		width: 28vw;
		height: 51px;
		display: inline-flex;
		position: relative;
		justify-content: flex-end;
		align-items: center;
	}
	.body-form-code image{
		width: 100%;
		height: auto;
	}
	.fixed-div {
		width: 100%;
		height: 17vw;
		position: fixed;
		top: 70%;
		left: 0;
		z-index: 10;
	}
	
	.fixed-div image {
		width: 40%;
		height: auto;
		margin-left: 50%;
	}
	.bottom-btn{
		width: 90%;
		height: 205px;
		position: fixed;
		bottom: 0;
		left: 5%;;
	}
	.btn-next{
		width: 100%;
		height: 90upx;
		line-height: 90upx;
		margin: 80px 0;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
		background-color: #007AFF;
		border: 1px solid #007AFF;
		color: #fff;
	}
</style>
